<?php

require('base.php');

class Work extends Base {
	
	function Work() {
		parent::Base();
		$this->database();
	}
	
	function index($language) {
		$this->language( $language, 'base' );
		$this->lib('pagination');
		
		$service_list = $this->db->find("select * from service where language='$language'");
		
		$total = $this->db->count('work', "language='$language'");
		
		$config = array(
			'total_row' => $total,
			'page_size' => 8
		);
		$this->pagination->init( $config );
		
		$sql = "select w.name, w.summary, w.url_pattern, s.url_pattern as parent_url_pattern from work w, service_work sw, service s "
			."where sw.work_id=w.id and sw.service_id=s.id and w.language='$language' order by w.created desc limit " 
			. $this->pagination->start_row . "," . $this->pagination->page_size;
			
		$work_list = $this->db->find($sql);
		
		$page = $this->db->find_row("select * from page where language='$language' and url_pattern='works'");
		$meta = array(
			'title' 		=> $page['title'],
			'keywords'		=> $page['keywords'],
			'description'	=> $page['description']
		);
		
		$data = array(
			'service_list' 	=> $service_list,
			'work_list' 	=> $work_list,
			'meta'			=> $meta
		);
		$this->layout('portal/work_list', $data);
	}
	
	function workList($up, $language) {
		$this->language( $language, 'base' );
		
		$service_list = $this->db->find("select * from service where language='$language'");
		
		$this->lib('pagination');
		$sql = "select count(*) from service_work sw, work w where sw.work_id=w.id and sw.service_id="
			."(select id from service where language='$language' and url_pattern='$up')";
		
		$total = $this->db->find_var($sql);
		$config = array(
			'total_row' => $total,
			'page_size' => 8
		);
		$this->pagination->init( $config );

		$sql = "select w.name, w.summary, w.url_pattern, s.url_pattern as parent_url_pattern from service_work sw, work w, service s "
			."where sw.work_id=w.id and sw.service_id=s.id and sw.service_id=(select id from service where language='$language' and url_pattern='$up') "
			."order by w.created desc limit " . $this->pagination->start_row . "," . $this->pagination->page_size;

		$work_list = $this->db->find($sql);	
		
		$page = $this->db->find_row("select * from page where language='$language' and url_pattern='works'");
		$meta = array(
			'title' 		=> $page['title'],
			'keywords'		=> $page['keywords'],
			'description'	=> $page['description']
		);
		
		$data = array(
			'service_list' 	=> $service_list,
			'work_list' 	=> $work_list,
			'meta'			=> $meta
		);
		$this->layout('portal/work_list', $data);
	}
	
	function show($up, $language) {
		$this->language( $language, 'base' );
		$service_list = $this->db->find("select * from service where language='$language'");
		
		$work = $this->db->find_row("select * from work where language='$language' and url_pattern='$up'");
		
		$meta = array(
			'title' 		=> $work['title'],
			'keywords'		=> $work['keywords'],
			'description'	=> $work['description']
		);
		
		$data = array(
			'service_list' => $service_list,
			'work' => $work
		);
		$this->layout('portal/work', $data);
	}

}

?>